package org.dentalcard.ui.api.tools;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import java.awt.*;

/**
 * @user: Vladimir Chernishov
 * @date: 21.12.11
 * @time: 15:27
 */
public class ComponentTableEditor extends AbstractCellEditor implements TableCellEditor {

    private Component panel;
    private JTextField field = new JTextField();
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        if(value != null && value instanceof Component){
            panel = (Component) value;
            return panel;
        } else {
            panel = null;
            field.setText(String.valueOf(value));
            return field;
        }
    }

    @Override
    public Object getCellEditorValue() {
        if(panel != null){
            return panel;
        } else {
            return field.getText();
        }
    }
}
